<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="服务对象姓名" prop="name">
        <el-input
            v-model="queryParams.name"
            placeholder="请输入服务对象姓名"
            clearable
            @keyup.enter="handleQuery"
            style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <div style="display: flex;align-items: center">
          <el-input
              v-model="queryParams.age"
              placeholder="请填写"
              clearable
              @keyup.enter="handleQuery"
              style="width: 100px"
          />
          <div style="margin: 0 8px;">至</div>
          <el-input
              v-model="queryParams.age"
              placeholder="请填写"
              clearable
              @keyup.enter="handleQuery"
              style="width: 100px"
          />
        </div>
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="queryParams.gender" placeholder="请选择性别" clearable style="width: 240px">
          <el-option
              v-for="dict in sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="居住地址" prop="nowProvince">
        <el-input
            v-model="queryParams.nowProvince"
            placeholder="请输入居住地址"
            clearable
            @keyup.enter="handleQuery"
            style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="所属社区" prop="community">
        <el-input
            v-model="queryParams.community"
            placeholder="请输入所属社区"
            clearable
            @keyup.enter="handleQuery"
            style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="服务对象类型" prop="serviceObjectCategory">
        <el-select v-model="queryParams.serviceObjectCategory" placeholder="请选择服务对象类型" clearable
                   style="width: 240px">
          <el-option
              v-for="dict in service_object_category"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="住养类别" prop="careType">
        <el-select v-model="queryParams.careType" placeholder="请选择住养类别" clearable
                   style="width: 240px">
          <el-option
              v-for="dict in residential_care_category"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
        >导出
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!--   @selection-change="handleSelectionChange"
          <el-table-column type="selection" width="55" align="center" /> -->
    <el-table v-loading="loading" :data="elderlyList">
      <el-table-column label="序号" align="center" type="index" width="60"/>
      <el-table-column label="档案编号" align="center" prop="no"/>
      <el-table-column label="头像" align="center" prop="avatar" width="100">
        <template #default="scope">
          <el-avatar :size="50" :src="scope.row.avatar || url"/>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="身高（cm）" align="center" prop="height"/>
      <el-table-column label="体重（kg）" align="center" prop="weight"/>
      <el-table-column label="性别" align="center" prop="gender">
        <template #default="scope">
          <dict-tag :options="sys_user_sex" :value="scope.row.gender"/>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age"/>
      <el-table-column label="服务机构" align="center" prop="nursinghome"/>
      <el-table-column label="所属社区" align="center" prop="community"/>
      <el-table-column label="居住地址" align="center" prop="nowDetailedLocation" :show-overflow-tooltip="true"/>
      <el-table-column label="服务对象类别" align="center" prop="serviceObjectCategory" width="200">
        <template #default="scope">
          <dict-tag :options="service_object_category" :value="scope.row.serviceObjectCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="住养类别" align="center" prop="careType">
        <template #default="scope">
          <dict-tag :options="residential_care_category" :value="scope.row.careType"/>
        </template>
      </el-table-column>
      <el-table-column label="失能等级" align="center" prop="disabilityLevel">
        <template #default="scope">
          <dict-tag :options="disability_grade" :value="scope.row.disabilityLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template #default="scope">
          <el-button
              type="text"
              icon="View"
              @click="handleDetails(scope.row)"
          >查看
          </el-button>
          <el-button
              type="text"
              icon="Edit"
              @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
              type="text"
              icon="Delete"
              @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改人员信息对话框 -->
    <el-drawer :title="title" v-model="open" size="60%" :before-close="handleClose">
      <el-form ref="elderlyRef" :model="form" :rules="rules" label-width="110px">
        <el-row :gutter="20">
          <el-col :span="16">
            <el-form-item label="档案编号" prop="no">
              <el-input v-model="form.no" disabled placeholder="请输入档案编号">
                <template #append>
                  <el-button type="primary" style="background-color: #409eff; border-color: #409eff; color: white;"
                             @click="getNo">生成编号
                  </el-button>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="一卡通卡号" prop="cardNumber">
              <el-input v-model="form.cardNumber" placeholder="请输入一卡通卡号"/>
            </el-form-item>
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名"/>
            </el-form-item>
            <el-form-item label="性别">
              <el-select v-model="form.gender" placeholder="请选择性别">
                <el-option
                    v-for="dict in sys_user_sex"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="年龄" prop="age">
              <el-input v-model="form.age" placeholder="请输入年龄"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="头像">
              <image-upload v-model="form.avatar" :limit="1"/>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="出生日期" prop="birthDate">
              <el-date-picker clearable
                              v-model="form.birthDate"
                              type="date"
                              value-format="YYYY-MM-DD"
                              placeholder="请选择出生日期"
                              style="width: 100%">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="联系电话" prop="contactPhone">
              <el-input v-model="form.contactPhone" placeholder="请输入联系电话"/>
            </el-form-item>
            <el-form-item label="证件类型" prop="idType">
              <el-select v-model="form.idType" placeholder="请选择证件类型">
                <el-option
                    v-for="dict in document_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="身份证号" prop="idNumber">
              <el-input v-model="form.idNumber" placeholder="请输入身份证号"/>
            </el-form-item>
            <el-form-item label="身高" prop="height">
              <el-input v-model="form.height" placeholder="请输入身高">
                <template #append>cm</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="身份证件照">
              <image-upload v-model="form.idPhoto" :limit="2"/>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="体重" prop="weight">
              <el-input v-model="form.weight" placeholder="请输入体重">
                <template #append>kg</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="民族" prop="ethnicity">
              <el-select v-model="form.ethnicity" placeholder="请选择民族">
                <el-option
                    v-for="dict in nation_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="婚姻状况" prop="maritalStatus">
              <el-select v-model="form.maritalStatus" placeholder="请选择婚姻状况">
                <el-option
                    v-for="dict in marital_status"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="配偶姓名" prop="spouseName">
              <el-input v-model="form.spouseName" placeholder="请输入配偶姓名"/>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="服务对象类型" prop="serviceObjectCategory">
              <el-select v-model="form.serviceObjectCategory" placeholder="请选择服务对象类型">
                <el-option
                    v-for="dict in service_object_category"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生日提醒">
              <el-radio-group v-model="form.birthdayReminder">
                <el-radio
                    v-for="dict in birthday_reminder"
                    :key="dict.value"
                    :label="dict.value"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="失能等级" prop="disabilityLevel">
              <el-select v-model="form.disabilityLevel" placeholder="请选择失能等级">
                <el-option
                    v-for="dict in disability_grade"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="文化程度" prop="educationLevel">
              <el-select v-model="form.educationLevel" placeholder="请选择文化程度">
                <el-option
                    v-for="dict in educational_level"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="居住类型" prop="residenceType">
              <el-select v-model="form.residenceType" placeholder="请选择居住类型">
                <el-option
                    v-for="dict in residential_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="政治面貌">
              <el-select v-model="form.politicalStatus" placeholder="请选择政治面貌">
                <el-option
                    v-for="dict in political_status"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="住养类别" prop="careType">
              <el-select v-model="form.careType" placeholder="请选择住养类别">
                <el-option
                    v-for="dict in residential_care_category"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所操方言" prop="dialect">
              <el-input v-model="form.dialect" placeholder="请输入所操方言"/>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="宗教信仰" prop="religiousBelief">
              <el-select v-model="form.religiousBelief" placeholder="请选择宗教信仰">
                <el-option
                    v-for="dict in religious_belief"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="国籍" prop="nationality">
              <el-select v-model="form.nationality" placeholder="请选择国籍">
                <el-option
                    v-for="(item,index)  in dataList"
                    :key="index"
                    :label="item.name_zh"
                    :value="item.name_zh"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="所属社区" prop="community">
              <el-input v-model="form.community" placeholder="请输入所属社区"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="户口详细地址" prop="householdProvince">
              <el-select v-model="form.householdProvince" @change="chooseProvince(0)" placeholder="请选择省份"
                         class="select-box">
                <el-option
                    v-for="(item,index) in provinceList"
                    :key="index"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
              </el-select>
              <el-select v-model="form.householdCity" @change="chooseCity(0)" :disabled="!form.householdProvince"
                         placeholder="请选择城市"
                         class="select-box">
                <el-option
                    v-for="(item,index) in cityList"
                    :key="index"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
              </el-select>
              <el-select v-model="form.householdDistrict" @change="chooseRegion(0)" :disabled="!form.householdCity"
                         placeholder="请选择区域"
                         class="select-box">
                <el-option
                    v-for="(item,index) in regionList"
                    :key="index"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
              </el-select>
              <el-select v-model="form.householdStreet" :disabled="!form.householdDistrict" placeholder="请选择街道"
                         class="select-box">
                <el-option
                    v-for="(item,index) in streetList"
                    :key="index"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="户口详细地址" prop="householdAddress">
              <el-input v-model="form.householdAddress" placeholder="请输入户口详细地址"/>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="户籍地址识别" prop="householdAddress">
              <el-input
                  v-model="textarea"
                  :rows="6"
                  type="textarea"
                  placeholder="智能解析:粘贴或者输入整段文字，自动识别省市区街道，如:广东省广州市越秀区黄花岗街道新达广场南座1609号"
              />
              <el-button class="btn_" size="small" type="success" @click="handleClick(1,textarea)">识别</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="现住地址" prop="nowProvince">
              <el-select v-model="form.nowProvince" @change="chooseProvince(1)" placeholder="请选择省份"
                         class="select-box">
                <el-option
                    v-for="(item,index) in provinceList"
                    :key="index"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
              </el-select>
              <el-select v-model="form.nowCity" @change="chooseCity(1)" :disabled="!form.nowProvince"
                         placeholder="请选择城市"
                         class="select-box">
                <el-option
                    v-for="(item,index) in cityList"
                    :key="index"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
              </el-select>
              <el-select v-model="form.nowRegion" @change="chooseRegion(1)" :disabled="!form.nowCity"
                         placeholder="请选择区域" class="select-box">
                <el-option
                    v-for="(item,index) in regionList"
                    :key="index"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
              </el-select>
              <el-select v-model="form.nowStreet" :disabled="!form.nowRegion" placeholder="请选择街道"
                         class="select-box">
                <el-option
                    v-for="(item,index) in streetList"
                    :key="index"
                    :label="item.name"
                    :value="item.name"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="现住详细位置" prop="nowDetailedLocation">
              <el-input v-model="form.nowDetailedLocation" placeholder="请输入现住详细位置"/>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="现住地址识别" prop="householdAddress">
              <el-input
                  v-model="textarea1"
                  :rows="6"
                  type="textarea"
                  placeholder="智能解析:粘贴或者输入整段文字，自动识别省市区街道，如:广东省广州市越秀区黄花岗街道新达广场南座1609号"
              />
              <el-button class="btn_" size="small" type="success" @click="handleClick(2,textarea1)">识别</el-button>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="门头照">
          <image-upload v-model="form.storefrontPhoto" limit="3"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-drawer>
  </div>
</template>

<script setup name="Elderly">
import dataAll from '@/api/pcas-code.js'
import dataList from "@/api/nationality.js";
import router from "@/router/index.js";
import {
  addServiceObject,
  delServiceObject, getServiceObjectNo,
  listServiceObject,
  updateServiceObject
} from "@/views/record/serviceObject/api/serviceObject.js";

const {proxy} = getCurrentInstance();
const {
  marital_status,
  residential_care_category,
  political_status,
  service_object_category,
  religious_belief,
  disability_grade,
  birthday_reminder,
  educational_level,
  document_type,
  sys_user_sex,
  residential_type,
  nation_type
} = proxy.useDict('marital_status', 'residential_care_category', 'political_status', 'service_object_category', 'religious_belief', 'disability_grade', 'birthday_reminder', 'educational_level', 'document_type', 'sys_user_sex', 'residential_type', 'nation_type');

const elderlyList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const provinceList = ref([]);
const cityList = ref([]);
const regionList = ref([]);
const streetList = ref([]);
const url = ref('https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png')
const textarea = ref('')
const textarea1 = ref('')

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    nursinghome: null,
    name: null,
    gender: null,
    age: null,
    no: null,
    contactPhone: null,
    avatar: null,
    idType: null,
    idNumber: null,
    idPhoto: null,
    idPictureAgainst: null,
    birthDate: null,
    height: null,
    weight: null,
    ethnicity: null,
    maritalStatus: null,
    spouseName: null,
    emergencyContactPhone: null,
    educationLevel: null,
    politicalStatus: null,
    dialect: null,
    religiousBelief: null,
    nationality: null,
    householdProvince: null,
    householdCity: null,
    householdDistrict: null,
    householdStreet: null,
    householdAddress: null,
    storefrontPhoto: null,
    community: null,
    nowProvince: null,
    nowCity: null,
    nowRegion: null,
    nowStreet: null,
    nowDetailedLocation: null,
    serviceObjectCategory: null,
    disabilityLevel: null,
    residenceType: null,
    careType: null,
    birthdayReminder: null,
    remark: null,
  },
  rules: {
    name: [
      {required: true, message: "名称不能为空", trigger: "blur"}
    ],
    no: [
      {required: true, message: "档案编号不能为空", trigger: "blur"}
    ],
    nowDetailedLocation: [
      {required: true, message: "现居住地址不能为空", trigger: "blur"}
    ],
  }
});

const {queryParams, form, rules} = toRefs(data);

getList();

onMounted(() => {
  provinceList.value = dataAll
})

function handleClick(type, address) {
  let province = provinceList.value.filter(item => address.includes(item.name));
  let city = province || null;
  let region = city || null;
  let street = region || null;
  let desc = address;
  if (province && province.length > 0) {
    city = province[0].children.filter(item => address.includes(item.name))
    desc = desc.replace(province[0].name, '').trim();
    if (city) {
      region = city[0].children.filter(item => address.includes(item.name));
      desc = desc.replace(city[0].name, '').trim();
      if (region) {
        street = region[0].children.filter(item => address.includes(item.name));
        desc = desc.replace(region[0].name, '').trim();
        if (street) desc = desc.replace(street[0].name, '').trim();
      }
    }
  }
  // 户籍
  if (type == 1) {
    form.value.householdProvince = province[0].name
    form.value.householdCity = city[0].name
    form.value.householdDistrict = region[0].name
    form.value.householdStreet = street[0].name
    form.value.householdAddress = desc
  }
  // 现住址
  if (type == 2) {
    form.value.nowProvince = province[0].name
    form.value.nowCity = city[0].name
    form.value.nowRegion = region[0].name
    form.value.nowStreet = street[0].name
    form.value.nowDetailedLocation = desc
  }
}

function handleClose() {
  proxy.$modal.confirm('是否确定关闭此窗口？')
      .then(() => {
        open.value = false
      })
      .catch(() => {
        // catch error
      })
}

function getNo() {
  getServiceObjectNo().then(res => {
    form.value.no = res.data
  })
}

function chooseProvince(type) {
  // 户口
  if (type == 0) {
    let province = provinceList.value.find(item => item.name == form.value.householdProvince)
    cityList.value = province.children
  }
  // 现居住地
  if (type == 1) {
    let province = provinceList.value.find(item => item.name == form.value.nowProvince)
    cityList.value = province.children
  }
}

function chooseCity(type) {
  // 户口
  if (type == 0) {
    let province = cityList.value.find(item => item.name == form.value.householdCity)
    regionList.value = province.children
  }
  // 现居住地
  if (type == 1) {
    let province = cityList.value.find(item => item.name == form.value.nowCity)
    regionList.value = province.children
  }
}

function chooseRegion(type) {
  // 户口
  if (type == 0) {
    let province = regionList.value.find(item => item.name == form.value.householdDistrict)
    streetList.value = province.children
  }
  // 现居住地
  if (type == 1) {
    let province = regionList.value.find(item => item.name == form.value.nowRegion)
    streetList.value = province.children
  }
}


/** 查询人员信息列表 */
function getList() {
  loading.value = true;
  listServiceObject(queryParams.value).then(response => {
    elderlyList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    nursinghome: null,
    name: null,
    gender: "0",
    age: null,
    no: null,
    contactPhone: null,
    avatar: null,
    idType: null,
    idNumber: null,
    idPhoto: null,
    idPictureAgainst: null,
    birthDate: null,
    height: null,
    weight: null,
    ethnicity: null,
    maritalStatus: null,
    spouseName: null,
    emergencyContactPhone: null,
    educationLevel: null,
    politicalStatus: null,
    dialect: null,
    religiousBelief: null,
    nationality: null,
    householdProvince: null,
    householdCity: null,
    householdDistrict: null,
    householdStreet: null,
    householdAddress: null,
    storefrontPhoto: null,
    community: null,
    nowProvince: null,
    nowCity: null,
    nowRegion: null,
    nowStreet: null,
    nowDetailedLocation: null,
    serviceObjectCategory: null,
    disabilityLevel: null,
    residenceType: null,
    careType: null,
    birthdayReminder: "0",
    remark: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    deleteStatus: "0"
  };
  proxy.resetForm("elderlyRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加人员信息";
}

/** 查看按钮操作 */
function handleDetails(row) {
  router.push({
    path: "/customer_management/elderly_management/elderlyInfo",
    query: {
      id: row.id,
      ifEdit: false
    },
  });
}

/** 修改按钮操作 */
function handleUpdate(row) {
  // reset();
  // const _id = row.id || ids.value
  // gecontactPhonederly(_id).then(response => {
  //   form.value = response.data;
  //   open.value = true;
  //   title.value = "修改人员信息";
  // });
  router.push({
    path: "/customer_management/elderly_management/elderlyInfo",
    query: {
      id: row.id,
      ifEdit: true
    },
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["elderlyRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateServiceObject(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addServiceObject(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除此数据？').then(function () {
    return delServiceObject(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('serviceTarget/elderly/export', {
    ...queryParams.value
  }, `elderly_${new Date().getTime()}.xlsx`)
}

</script>
<style scoped>
.resident-address {
  display: flex;
  align-items: center;
}

.select-box {
  width: 200px;
  margin-right: 10px;
}

.btn_ {
  position: absolute;
  right: 5px;
  bottom: 5px;
}
</style>